<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>物品</title>
</head>
<body>
	<form action="/Home/Goods/addfood" method="post" onsubmit="return false;">
		名称:<input type="text" name="name" value="" id="name"><br><br>
		<button id="btn">添加</button>
	</form>
	<div style="border: 1px solid green;float: right;width: 400px;height: 500px;" id="p">
		<foreach name="data" item="val" key="k">
			{$val['name']}<br>
		</foreach>
	</div>
	<!-- <div style="border: 1px solid red;width:100px;height: 100px;" id="p"></div> -->
</body>
</html>
<script type="text/javascript" src="/Public/js/jquery-1.11.2.min.js"></script>
<script type="text/javascript">
$('#btn').on('click',function(){
	var name = $('#name').val();
	// alert(name);
	var url = '/Home/Goods/addfood';
	var data = {'name':name};
	$.post(url,data,function(res){
		if(res.status == 0)
		{
			alert(res.content);
		}else if(res.status == 1)
		{
			alert(res.content);
			shuaxin();
		}
	},'json');
});

function shuaxin(){
	$.post('/Home/Goods/food',{'status':0},function(data){
		var str = '';
		if(data)
		{
			for(var val in data){  
		        str += data[val].name+"<br>"
		    }

		    $('#p').html(str);
		}
	},'json');
}

$().ready(function() {
 
     $("#p").mouseover( function() {
          this.style.border = "none";

          $(this).hide();
     }).mouseout( function(){
          this.style.border = "solid 2px #6600FF";
          // 
          $(this).show();
     });



       
 
});
</script>